package com.treehouse.application;

import java.util.LinkedList;

import com.treehouse.gui.actorview.ActorViewController;
import com.treehouse.gui.actorview.IActorViewController;
import com.treehouse.gui.consoleview.ConsoleViewController;
import com.treehouse.gui.consoleview.IConsoleViewController;
import com.treehouse.gui.loaderview.ILoaderViewController;
import com.treehouse.gui.loaderview.LoaderViewController;
import com.treehouse.gui.viewport.IViewPortController;
import com.treehouse.gui.viewport.ViewPortController;
import com.treehouse.pornstar.Pornstar;
import com.treehouse.pornstar.services.IPornstarServices;
import com.treehouse.pornstar.services.impl.PornstarServicesImpl;
import com.treehouse.properties.CrawlerProperties;
import com.treehouse.properties.ICrawlerProperties;
import com.treehouse.service.application.ApplicationService;
import com.treehouse.service.application.IApplicationService;
import com.treehouse.service.loader.ILoaderService;
import com.treehouse.service.loader.LoaderService;
import com.treehouse.sql.mysql.MySqlDatabase;
import com.treehouse.url.HTMLParser;
import com.treehouse.url.farmer.IURLFarmer;
import com.treehouse.url.farmer.URLFarmer;
import com.treehouse.url.loader.ISceneLoader;
import com.treehouse.url.loader.TrailerLoader;

public class Application {

	public void initialize(){

		// Initialize Services
		ICrawlerProperties properties = new CrawlerProperties(
				"ressources\\main.properties");
		IApplicationService applicationService = new ApplicationService(properties);
		
		
		MySqlDatabase msqlDB = new MySqlDatabase("Local MySQL", "localhost", 3306, "root", "okgf8abl", "brazz_db");
		
		
		IPornstarServices pornstarServices = new PornstarServicesImpl(applicationService, msqlDB.getConnection());
		ILoaderService loaderService = new LoaderService();

		// Initialize View
		IActorViewController actorViewController = new ActorViewController(
				applicationService, pornstarServices);
		ILoaderViewController loaderViewController = new LoaderViewController(
				applicationService);
		IConsoleViewController consoleViewController = new ConsoleViewController(
				applicationService);
		IViewPortController viewPortController = new ViewPortController(
				consoleViewController, actorViewController,
				loaderViewController, applicationService);
		viewPortController.setVisible(true);

		
		//Reload if required
		if (pornstarServices.hasToReload()) {

			HTMLParser parser = new HTMLParser();
			IURLFarmer farmer = new URLFarmer(
					properties.getProperty("pornstarentry"),
					properties.getProperty("domain"), parser);
			ISceneLoader loader = new TrailerLoader(
					properties.getProperty("scenedirectory"), farmer, parser);

			LinkedList<Pornstar> list = farmer.getPornstarList();

		}
		/*
		 * ViewPort view = new
		 * ViewPort(properties.getProperty("applicationname") + " " +
		 * properties.getProperty("version"), farmer, loader, list);
		 * view.setVisible(true);
		 */
	}
}
